package com.bjdd.jdy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjdd.jdy.base.BaseListAdapter;
import com.bjdd.jdy.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yukai on 2016/11/22.
 */

public class FileAdapter extends BaseListAdapter<String> {
    public FileAdapter(Context context, List<String> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_file, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mTvFile.setText(getItem(position));

        holder.mIvFileClose.setOnClickListener(v -> {
            removeEntity(getItem(position));
            notifyDataSetChanged();
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_file)
        TextView mTvFile;
        @Bind(R.id.iv_file_close)
        ImageView mIvFileClose;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
